package com.heiyu.utils;

import java.math.BigDecimal;

/**
 * Created by mountain on 18/6/13.
 */
public class RangeUtil {

    public static String formatter(BigDecimal val){
        if(val == null){
            return "0.00%";
        }
        if(val.doubleValue()>0){
            return "+"+val.divide(new BigDecimal("1.00"),2,2)+"%";
        }
        return val.divide(new BigDecimal("1.00"),2,2)+"%";
    }

    public static String formatterNoFlag(BigDecimal val){
        if(val == null){
            return "0.00%";
        }
        return val.divide(new BigDecimal("1.00"),2,2)+"%";
    }

    public static String diffPrice(BigDecimal price,BigDecimal range){
            if(range == null){
                return "0.00";
            }
            price = price.divide(range.add(new BigDecimal("100")).divide(new BigDecimal("100")),2,4);
            if(range.doubleValue()>0){
                return "+"+price.multiply(range).divide(new BigDecimal(100),2,4).toString();
            }
            return price.multiply(range).divide(new BigDecimal(100),2,4).toString();
    }
}
